/**
 * Copyright (c) 2017-2017 All Rights Reserved.
 */
package com.zbest.zpay.exchange.biz.action.pay;

import java.util.HashMap;
import java.util.Map;

import org.springframework.stereotype.Service;

import com.zbest.zpay.exchange.dal.model.FluxInfoDO;
import com.zbest.zpay.exchange.integration.gw.GwClient;
import com.zbest.zpay.service.exchange.FinCardPayRequest;
import com.zbest.zpay.service.exchange.model.FluxKeyEnum;
import com.zbest.zpay.service.gw.model.GwKeyEnum;
import com.zbest.zpay.service.gw.model.GwResult;
import com.zbest.zpay.service.paycore.model.PaycoreKeyEnum;
import com.zbest.zpay.shared.process.BaseAction;
import com.zbest.zpay.shared.process.ProcessResult;

/**
 * 
 *
 * @author Administrator
 * @version $Id: SendGwAction.java, v 0.1 2017-4-16 下午1:29:35 Administrator Exp $
 */
@Service("sendGwAction")
public class SendGwAction extends BaseAction {

    private GwClient gwClient;

    /** 
     * @see com.zbest.zpay.shared.process.BaseAction#perform(com.zbest.zpay.shared.process.ProcessResult)
     */
    @Override
    public void perform(ProcessResult processResponse) {

        FinCardPayRequest request = getValue(FluxKeyEnum.FIN_CARD_PAY_REQUEST.getCode());
        FluxInfoDO fluxInfoDO = getValue(FluxKeyEnum.FLUX_INFO_DO.getCode());

        Map<String, Object> data = new HashMap<String, Object>();
        data.put(GwKeyEnum.CURRENCY.getCode(), fluxInfoDO.getCurrency());
        data.put(GwKeyEnum.GOODS_TITLE.getCode(),
            request.getExtPros().get(PaycoreKeyEnum.GOODS_TITLE.getCode()));
        data.put(GwKeyEnum.INST_SERIAL_NO.getCode(), fluxInfoDO.getInstSerialNo());
        data.put(GwKeyEnum.TOTAL_AMOUNT.getCode(), String.valueOf(fluxInfoDO.getAmount()));
        GwResult gwResult = gwClient.syncSend(request.getChannelId(), data);

        setValue(FluxKeyEnum.GW_RESULT.getCode(), gwResult);
    }

    public void setGwClient(GwClient gwClient) {
        this.gwClient = gwClient;
    }
    
}
